/*
 * File:   TreeTest.cpp
 * Author: KENNJI
 *
 * Created on Mar 25, 2013, 9:20:25 PM
 */

#include "TreeTest.h"
#include "../../src/Tree/ZipTree.h"
#include "../../src/Tree/DirectoryNode.h"
#include "../../src/Tree/ZipNode.h"
#include<string.h>


CPPUNIT_TEST_SUITE_REGISTRATION(TreeTest);

TreeTest::TreeTest()
{

}

TreeTest::~TreeTest()
{
}

void TreeTest::setUp()
{
}

void TreeTest::tearDown()
{
}

void TreeTest::itShouldDefineTheRootWhenTheFirstItemIsAddedToTree()
{
    ZipTree* treeToTest = new ZipTree();
    const char* name = "testElement";
    treeToTest->add(name, true);
    const char* rootActual = treeToTest->getRoot()->getRoot();
    const char* rootExpected = name;
    CPPUNIT_ASSERT(strcmp(rootActual, rootExpected) == 0);
}

void TreeTest::itShouldAddANodeToTree()
{
    const char* directoryName = "directory";
    DirectoryNode* directoryTest = new DirectoryNode(directoryName);
    const char* name = "testElement";
    ZipTree* treeToTest = new ZipTree(name);
    treeToTest->add(directoryTest);
    CPPUNIT_ASSERT(strcmp(treeToTest->getRoot()->getBranches()[0].getRoot(), directoryName) == 0);
}

void TreeTest::itShouldAddADirectoryNodeWhenConditionIsTrue()
{
    ZipTree* treeToTest = new ZipTree();
    const char* nodeName = "NodeTest";
    bool isDirectory = true;
    treeToTest->add(nodeName, isDirectory);
    CPPUNIT_ASSERT(treeToTest->getRoot()->isLeaf() == false);
}

void TreeTest::itShouldAddAFileNodeWhenConditionIsFalse()
{
    ZipTree* treeToTest = new ZipTree();
    const char* nodeName = "NodeTest";
    bool isDirectory = false;
    treeToTest->add(nodeName, isDirectory);
    CPPUNIT_ASSERT(treeToTest->getRoot()->isLeaf() == true);

}

void TreeTest::itShouldAddAnItemToASpecificNode()
{
    ZipTree* treeToTest = new ZipTree();
    const char* nodeName = "root";
    DirectoryNode* node = new DirectoryNode(nodeName);
    treeToTest->add(node);
    const char* fileName = "File Test";
    treeToTest->addToNode(fileName, false, nodeName);
    const char* actualdNodeName = treeToTest->getRoot()->getBranches()[0].getRoot();
    const char* expectedNodeName = fileName;
    CPPUNIT_ASSERT(strcmp(expectedNodeName, actualdNodeName) == 0);

}

void TreeTest::itShouldTraverseTheTree()
{
    ZipTree* tree = new ZipTree();
    tree->add("Root", true);
    tree->add("dir1", true);
    tree->add("dir2", true);
    tree->add("dir3", true);
    tree->addToNode("dir11", true, "dir1");
    char* expectedResult = "Root\ndir1\ndir11\ndir2\ndir3\n";
}


